package com.Prot2.Logger;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class GyroWorker {

		private SensorManager mSensorManager;
		private float avX,avY,avZ;
		
		public GyroWorker(Context c){
	    	mSensorManager= (SensorManager) c.getSystemService(Context.SENSOR_SERVICE);
	    	mSensorManager.registerListener(mAccelerationListener, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),(SensorManager.SENSOR_DELAY_FASTEST));

		}
		
		private SensorEventListener mAccelerationListener = new SensorEventListener() {

			@Override
			public void onAccuracyChanged(Sensor arg0, int arg1) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onSensorChanged(SensorEvent event) {
				if(event.sensor.getType() == Sensor.TYPE_GYROSCOPE){
					avX = event.values[0];
		        	avY = event.values[1];
		        	avZ = event.values[2];
				}
			}
			
		};
		
		public float getXAV(){
			return avX;
		}
		public float getYAV(){
			return avY;
		}
		public float getZAV(){
			return avZ;
		}
		public String getRead(String DELIMITER){
			return ""+avX+DELIMITER+avY+DELIMITER+avZ;
		}
		
		public void stop(){
			mSensorManager.unregisterListener(mAccelerationListener);
		}
		
	}

